package com.zealfi.wk.netty.server.handler.inbound;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * Created by kuan at 2018-03-20 下午 2:29
 */
public class MyServerHandler extends SimpleChannelInboundHandler<String> {
    private int count;

    @Override
    public void channelRead0(ChannelHandlerContext ctx, String msg) {
        System.out.println("The time server received order:" + msg + " ,the count is:" + ++count);

        String s = "Query Time Order".equalsIgnoreCase(msg) ? "SUCCESS! count is " + count : "BAD ORDER";
        ByteBuf message = Unpooled.copiedBuffer((s + System.getProperty("line.separator")).getBytes());
        ctx.writeAndFlush(message); //回复
    }

}
